﻿/// <reference path="BaseComplexInputListControl.js" />
/// <reference path="../General/StringBuilder.js" />

var $CheckBoxList = TA.Turbo.Controls.CheckBoxList = function CheckBoxList(clientId)
{
	if (Function.IsInherit(arguments)) return;

	this.BaseComplexInputListControl(clientId);
}
$CheckBoxList.Inherit(TA.Turbo.Controls.BaseComplexInputListControl);

var _____a;
if (_____a)
{
	$CheckBoxList.prototype = new $BaseComplexInputListControl();
	$CheckBoxList.prototype.BaseComplexInputListControl = new $BaseComplexInputListControl();
}

$CheckBoxList.prototype.Init = function Init()
{
	this.BaseComplexInputListControl.Init.call(this);
}

$CheckBoxList.prototype.get_Value = function get_Value()
{
	var sb = new StringBuilder();
	var first = true;
	for (var i = 0; i < this._inputs.length; ++i)
	{
		var input = this._inputs[i];

		if (input.checked)
		{
			if (!first)
				sb.Append(",");
			first = false;

			sb.Append(input.value);
		}
	}
	return sb.toString();
}
$CheckBoxList.prototype.set_Value = function set_Value(value)
{
	if (_____a)
		value = "";

	if (value == null) value = "";
	var parts = value.split(",");
	for (var i = 0; i < this._inputs.length; ++i)
	{
		var input = this._inputs[i];

		input.checked = parts.Contains(input.value);
	}
}


$CheckBoxList.prototype._CreateOptionElements = function _CreateOptionElements(item)
{
	if (_____a)
		item = new $ListItem();

	var elem = this._GetElement("LABEL");

	var input = this._GetElement("INPUT");
	input.type = "checkbox";
	elem.appendChild(input);
	this._inputs.push(input);

	var text = document.createTextNode(item.Text);
	elem.appendChild(text);


	if (this.get_RepeatDirection() == Orientation.Horizontal)
		return [elem];
	else
	{
		return [elem, this._GetElement("BR")];
	}
}
